package com.huipinche.view.impl;

import com.huipinche.view.HomePageView;

import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import com.huipinche.view.utils.*;

public class HomePageViewimpl  implements HomePageView  {
    final int WIDTH = 560;
    final int HEIGHT = 577;
    private BackGroundPanel contentPane;
    private JFrame jFrame;
    private int page = 0;
    private boolean flag = true;

    /**
     * Launch the application.
     */
    /*public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    HomePageViewimpl frame = new HomePageViewimpl();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }*/

    /**
     * Create the frame.
     */
    public void initialize(){
        jFrame = new JFrame("惠拼车-主页");
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jFrame.setBounds((ScreenUtils.getScreenWidth() - WIDTH) / 2,
                (ScreenUtils.getScreenHeight() - HEIGHT) / 2, WIDTH, HEIGHT);
        try {
            jFrame.setIconImage(ImageIO.read(new File(PathUtils.getRealPath("logo3.jpeg"))));
        } catch (IOException e) {
            e.printStackTrace();
        }
        Image image01=new ImageIcon(PathUtils.getRealPath("bigbackground01.png")).getImage();
        contentPane = new BackGroundPanel(image01);
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        jFrame.setContentPane(contentPane);
        contentPane.setLayout(null);

        Icon confirm = new ImageIcon((PathUtils.getRealPath("car3.png")));
        Icon read = new ImageIcon((PathUtils.getRealPath("car2.png")));
        Icon back = new ImageIcon((PathUtils.getRealPath("car3.png")));


        JButton btnNewButton = new JButton("发布拼单");
        btnNewButton.setIcon(confirm);
        HomePageViewimpl temp = this;
        btnNewButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                temp.page = 210;//launchpage;
                temp.flag = false;
            }
        });
        btnNewButton.setBounds(38, 371, 140, 30);
        contentPane.add(btnNewButton);

        JButton btnNewButton_1 = new JButton("查看拼单");
        btnNewButton_1.setIcon(read);
        btnNewButton_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                temp.page = 230;//hallpage
                temp.flag = false;
            }
        });
        btnNewButton_1.setBounds(210, 371, 140, 30);
        contentPane.add(btnNewButton_1);

        JButton btnNewButton_2 = new JButton("退出程序");
        btnNewButton_2.setIcon(back);
        btnNewButton_2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new GeneralPageimpl("退出程序成功");//退出的程序
                jFrame.dispose();
            }
        });
        btnNewButton_2.setBounds(395, 371, 140, 30);
        contentPane.add(btnNewButton_2);

        JPanel panel = new JPanel();
        panel.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
        panel.setForeground(Color.ORANGE);
        panel.setBounds(10, 10, 515, 210);
        contentPane.add(panel);
        panel.setLayout(null);
        panel.setOpaque(false);

        JLabel btnNewButton_4 = new JLabel("拼单信息");
        btnNewButton_4.setForeground(Color.white);
        btnNewButton_4.setFont(new Font("楷体",Font.BOLD,18));
        btnNewButton_4.setBounds(0, 10, 93, 23);
        panel.add(btnNewButton_4);

        JTextArea textArea = new JTextArea();
        textArea.setText("\u5DF2\u6210\u56E2\uFF1A");
        textArea.setBounds(21, 43, 71, 35);
        textArea.setForeground(Color.white);//设置字体颜色
        textArea.setFont(new Font("楷体",Font.BOLD,16));//设置字体大小
        textArea.setEditable(false);//设置文本域不能被更改
        textArea.setOpaque(false);

        panel.add(textArea);

        JTextArea textArea_1 = new JTextArea();
        textArea_1.setText("\u76EE\u7684\u5730\uFF1A\u91CD\u5E86\u89E3\u653E\u7891\r\n\u51FA\u53D1\u65F6\u95F4\uFF1A2021\u5E7412\u670831\u65E5 18:00");
        textArea_1.setBounds(102, 43, 379, 42);
        textArea_1.setForeground(Color.white);//设置字体颜色
        textArea_1.setFont(new Font("楷体",Font.BOLD,16));//设置字体大小
        textArea_1.setEditable(false);//设置文本域不能被更改
        textArea_1.setOpaque(false);

        panel.add(textArea_1);

        JTextArea textArea_2 = new JTextArea();
        textArea_2.setText("\u5DF2\u62FC3/4");
        textArea_2.setBounds(21, 103, 71, 35);
        textArea_2.setForeground(Color.white);//设置字体颜色
        textArea_2.setFont(new Font("楷体",Font.BOLD,16));//设置字体大小
        textArea_2.setEditable(false);//设置文本域不能被更改
        textArea_2.setOpaque(false);

        panel.add(textArea_2);

        JTextArea textArea_3 = new JTextArea();
        textArea_3.setText("\u5DF2\u62FC1/4");
        textArea_3.setBounds(21, 158, 72, 42);
        textArea_3.setForeground(Color.white);//设置字体颜色
        textArea_3.setFont(new Font("楷体",Font.BOLD,16));//设置字体大小
        textArea_3.setEditable(false);//设置文本域不能被更改
        textArea_3.setOpaque(false);

        panel.add(textArea_3);

        JTextArea textArea_4 = new JTextArea();
        textArea_4.setText("\u76EE\u7684\u5730\uFF1A\u5317\u4EAC\u5929\u5B89\u95E8\r\n\u51FA\u53D1\u65F6\u95F4\uFF1A2021\u5E7412\u670831\u65E5 18:00");
        textArea_4.setBounds(102, 103, 379, 45);
        textArea_4.setForeground(Color.white);//设置字体颜色
        textArea_4.setFont(new Font("楷体",Font.BOLD,16));//设置字体大小
        textArea_4.setEditable(false);//设置文本域不能被更改
        textArea_4.setOpaque(false);

        panel.add(textArea_4);

        JTextArea textArea_5 = new JTextArea();
        textArea_5.setText("\u76EE\u7684\u5730\uFF1A\u957F\u6625\u7EA2\u65D7\u8857\r\n\u51FA\u53D1\u65F6\u95F4\uFF1A2021\u5E7412\u670831\u65E5 18:00");
        textArea_5.setBounds(103, 158, 378, 42);
        textArea_5.setForeground(Color.white);//设置字体颜色
        textArea_5.setFont(new Font("楷体",Font.BOLD,16));//设置字体大小
        textArea_5.setEditable(false);//设置文本域不能被更改
        textArea_5.setOpaque(false);

        panel.add(textArea_5);

        JButton btnNewButton_3 = new JButton("更多拼单信息......");
        btnNewButton_3.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                temp.page = 230;
                temp.flag = false;
            }
        });
        btnNewButton_3.setBounds(411, 241, 124, 23);
        contentPane.add(btnNewButton_3);

        jFrame.setResizable(false);
        jFrame.setVisible(true);


    }
    public HomePageViewimpl() {

    }
    @Override
    public int HomePage(boolean flag) throws InterruptedException {
            this.flag = flag;
            initialize();
            while(this.flag){
            Thread.sleep(200);
           };
           switch (page){
               case 210:
                  jFrame.removeNotify();
                   return 210;//发布拼单
               case 230:
                   jFrame.removeNotify();
                   return 230;//拼单大厅
           }
        return 0;
    }
}
